<template>
	<view class="content">
		<u-navbar leftIconColor="#fff" titleStyle="color:#fff" title="支付" bgColor="transparent" :autoBack="true"
			:placeholder="false">
		</u-navbar>
		<view style="height: 6vh;"></view>
		<view class="my-content">
			<view class="payment">
				<view class="entry">
					<view class="entry-left">
						<view class="entry-title">
							账户名称
						</view>
						<view class="entry-text">
							{{info.SK_NAME}}
						</view>
					</view>
					<view class="copy" @click="gocopy(info.SK_NAME)">
						复制
					</view>
				</view>
				<view class="entry">
					<view class="entry-left">
						<view class="entry-title">
							银行卡号
						</view>
						<view class="entry-text">
							{{info.BANK_NUM}}
						</view>
					</view>
					<view class="copy" @click="gocopy(info.BANK_NUM)">
						复制
					</view>
				</view>
				<view class="entry">
					<view class="entry-left">
						<view class="entry-title">
							银行名称
						</view>
						<view class="entry-text">
							{{info.BANK_ADDRESS}}
						</view>
					</view>
					<view class="copy" @click="gocopy(info.BANK_ADDRESS)">
						复制
					</view>
				</view>
				<view class="entry">
					<view class="entry-left">
						<view class="entry-title">
							银行开户行
						</view>
						<view class="entry-text" @click="gocopy(info.BANK_NAME)">
							{{info.BANK_NAME}}
						</view>
					</view>
					<view class="copy">
						复制
					</view>
				</view>
				<view class="entry">
					<view class="entry-left">
						<view class="entry-title">
							转账金额
						</view>
						<view class="entry-text">
							￥{{num}}
						</view>
					</view>
					<view class="copy" @click="gocopy(num)">
						复制
					</view>
				</view>
				<view class="content-title">
					转账人姓名：
				</view>
				<view class="entry1">
					<u--input maxlength="16" border="none" disabledColor="rgba(0,0,0,0.0)" color="#fff" v-model="name"
						placeholder="提示：请如实提交，以便审核。"></u--input>
				</view>
				<view class="code-box">
					<view class="item-title">
						上传转账截图
					</view>
					<view class="code" @click="upload">
						<image :src="'https://web.sunsk.top'+receive_qrcode" style="width:100%;height:240rpx"
							v-if="receive_qrcode" />
						<u-icon v-else class="icon" name="plus" color="#ffffff" size="28"></u-icon>
					</view>
				</view>
			</view>
			<view class="btn">
				<u-button color="#563AFD" type="primary" @click="gobay" text="提交"></u-button>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				receive_qrcode: '',
				info: {},
				num: 0,
				name: ''
			}
		},
		onLoad(e) {
			this.num = e.num
			this.payinfo()
		},
		methods: {
			gocopy(e) {
				uni.setClipboardData({
					data: e, //要被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({ //提示
							title: '复制成功',
							icon: 'none'
						})
					}
				});
			},
			gobay() {
				if (this.name == '') {
					uni.showToast({
						title: '请输入您的真实姓名！',
						icon: 'none'
					})
					return
				}
				if (this.receive_qrcode == '') {
					uni.showToast({
						title: '转账截图不可为空！',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					mask: true
				})
				this.$Request({
					method: 'POST',
					url: '/api/personal/rechange',
					data: {
						num: this.num,
						voucher: this.receive_qrcode,
						name: this.name
					}
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.receive_qrcode = ''
						this.name = ''
						uni.showToast({
							title:res.msg,
							icon: 'none'
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon: 'none'
						})
					}
				})
			},
			payinfo() {
				this.$Request({
					method: 'POST',
					url: '/api/personal/rechangeRender',
					data: {}
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data
					}
				})
			},
			upload() {
				let _self = this;
				//第一步:打开手机相册或者文件管理器选择文件
				uni.chooseImage({
					count: 1, //允许上传一张图片
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: function(res) {
						//获得选择好的文件,就算只有一个文件也是数组
						const tempFilePaths = res.tempFilePaths;
						uni.showLoading({
							mask: true
						})
						uni.uploadFile({
							url: '/api/upload/upload', //后端接口url
							filePath: tempFilePaths[0],
							header: {
								'Access-Control-Allow-Origin': '*', 
							},
							data: {
								token: uni.getStorageSync("token") || ''
							},
							name: 'file', //和后端接口需要的参数名一致
							success: (res) => {
								_self.receive_qrcode = JSON.parse(res.data).url
								uni.showToast({
									title: "成功",
									icon: "none"
								})
							},
							complete: (ok) => {
								uni.hideLoading()
							}
						})
					}
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #250F5A;
	}
</style>
<style lang="scss" scoped>
	.content {
		width: 100%;
		background: linear-gradient(90deg, #513AFD 0%, #F42FF9 54%, #F85B9F 100%);
		height: 568rpx;

		.my-content {
			background-color: #250F5A;
			border-top-right-radius: 40rpx;
			border-top-left-radius: 40rpx;
			padding: 30rpx;
			color: #fff;

			.head {
				display: flex;
				justify-content: space-between;

				padding: 30rpx 0;

				.head-item {
					width: 210rpx;
					font-size: 24rpx;
					padding: 30rpx 0;
					border-radius: 20rpx;
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;

					image {
						width: 26.77rpx;
						height: 25.5rpx;
						margin-right: 10rpx;
					}
				}

				.activity {
					background-color: #563AFD;
				}

				.stillness {
					background-color: rgba(255, 255, 255, .05);
				}
			}

			.payment {
				background-color: rgba(255, 255, 255, .05);
				padding: 30rpx;
				border-radius: 30rpx;
				margin-bottom: 30rpx;

				.entry1 {
					padding: 20rpx;
					background-color: rgba(238, 238, 238, 0.2);
					border-radius: 20rpx;
					margin-top: 20rpx;
				}

				.entry {
					padding: 20rpx 0rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 26rpx;
					color: #fff;
					margin-bottom: 20rpx;
					border-bottom: 1rpx solid rgba(255, 255, 255, 0.3);

					.entry-left {
						width: 80%;
						display: flex;
						align-items: center;

						.entry-title {
							width: 30%;
						}

						.entry-text {
							width: 70%;
							text-align: left;
						}
					}

					.copy {
						padding: 10rpx 20rpx;
						border-radius: 10rpx;
						background-color: #563AFD;
					}
				}

				.code-box {
					.item-title {
						color: #fff;
						font-size: 28rpx;
						font-weight: 600;
						padding: 30rpx 0;
					}

					.code {
						width: 240rpx;
						height: 240rpx;
						background-color: #250F5A;
						margin: 0 auto;
						position: relative;

						image {
							width: 240rpx;
							height: 240rpx;
						}

						.icon {
							width: 28px;
							position: absolute;
							top: 38%;
							left: 0;
							right: 0;
							margin: 0 auto;
						}
					}
				}

				.payment-item:first-child {
					margin: 0;
				}

				.payment-item:last-child {
					border: none;
					padding: 0;
				}
			}

			.btn {
				margin-top: 40rpx;
			}
		}
	}
</style>